// var a = 0;
var ini;
var times = 0;
var addNum = 0;
var getImg1 = "";
var getImag2 = "";
var getImag3 = "";
window.onload = function () {
  getEle();
  //定时，循环触发
  //默认图片
  //显示时候出现下一张
  //nextImg();
  self.setInterval("nextImg()",3000);
}

//获取元素
function getEle() {
  this.getImg1 = document.getElementById("image1");
  this.getImg2 = document.getElementById("image2");
  this.getImg3 = document.getElementById("image3");
}

function nextImg() {
  this.times = this.times + 1;
  this.ini = self.setInterval("moveImg()", 1);
  changeImg(times);
  reset();
}

function moveImg() {
  this.addNum = addNum + 1;
  var imgMargin = window.getComputedStyle(this.getImg1).marginLeft;
  imgMargin = parseFloat(imgMargin);
  imgMargin = imgMargin - 1.04;
  this.getImg1.style.marginLeft = imgMargin + "px";
  if(this.addNum == 500) {
    window.clearInterval(ini);
  }
}


function changeImg (time) {
  switch (time % 3) {
    case 1:
    this.getImg1.src = "../images/002.png";
    break;
    case 2:
    this.getImag2.src = "../images/003.png";
    break;
    default:
    this.getImag3.src = "../images/001.png";
  }
}

//复位css
function reset() {
  this.getImg1.style.marginLeft = "-520px";
}